package gui;

import java.awt.Dialog;
import java.awt.Frame;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import javax.swing.JFileChooser;
import manager.Manager;

public class CreateSpeciesWindow extends javax.swing.JFrame 
{
    //Whom to reference when setting values in the calling form
    private Frame parent;
    PickColorWindow pcw;
    
    /**
     * Opens file chooser. When valid file is chosen use it to fill in all
     * appropriate fields.
     **/
    void importSpecies()
    {
        try
        {
            JFileChooser jfc = new JFileChooser();
            jfc.showOpenDialog(this);
            Properties props = new Properties();
            props.load(new FileInputStream(jfc.getSelectedFile()));
            
        }
        catch (IOException e)
        {
            //Manager.unhandledException(e);
        }
    }
    
    /**
     * Closes CreateSpeciesWindow
     **/
    void cancelAdd()
    {
        setVisible(false);
    }
    /**
     * Adds selected species to species list on NewSimWindow and closes CreateSpeciesWindow
     **/
    void save()
    {
        boolean diet;
        if (btnDiet.getText().equalsIgnoreCase("Meat"))
        {
            diet = true;
        }
        else
        {
            diet = false;
        }
//        (NewSimWindow)(parent).speciesAdded(txtName.getText(), pnlColor.getBackground(), 
//                Integer.parseInt(txtHealth.getText()), Integer.parseInt(txtHunger.getText()), 
//                Integer.parseInt(txtSightRadius.getText()), Integer.parseInt(txtAttackPower.getText()), 
//                Integer.parseInt(txtWaitRegen.getText()), Integer.parseInt(txtGestationTime.getText()), 
//                Integer.parseInt(txtAtkCost.getText()), Integer.parseInt(txtMoveCost.getText()), 
//                Integer.parseInt(txtMateCost.getText()), Integer.parseInt(txtWaitCost.getText()), diet);
        setVisible(false);
    }
    
    /**
     * Opens PickColorWindow passing a reference to the color panel to be added
     */
    void pickColor()
    {
        pcw.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE);
        pcw.setVisible(true);
    }
    
    /**
     * If btnDiet says “meat” changes it to read “veggie”, and vice versa
     */
    void changeDiet()
    {
        if (btnDiet.getText().equalsIgnoreCase("meat"))
        {
            btnDiet.setText("Veggie");
        }
        else
        {
            btnDiet.setText("Meat");
        }
    }
    

    public CreateSpeciesWindow() 
    {
//        pcw = new PickColorWindow(this);
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        lblName = new javax.swing.JLabel();
        txtName = new javax.swing.JTextField();
        pnlColor = new javax.swing.JPanel();
        lblHealth = new javax.swing.JLabel();
        txtHealth = new javax.swing.JTextField();
        txtHunger = new javax.swing.JTextField();
        lblHunger = new javax.swing.JLabel();
        txtLifetime = new javax.swing.JTextField();
        lblLifetime = new javax.swing.JLabel();
        txtAttackPower = new javax.swing.JTextField();
        lblAttackPower = new javax.swing.JLabel();
        txtMoveCost = new javax.swing.JTextField();
        lblCosts = new javax.swing.JLabel();
        lblMoveCost = new javax.swing.JLabel();
        txtAtkCost = new javax.swing.JTextField();
        lblAtkCost = new javax.swing.JLabel();
        txtMateCost = new javax.swing.JTextField();
        lblMateCost = new javax.swing.JLabel();
        txtWaitCost = new javax.swing.JTextField();
        lblWaitCost = new javax.swing.JLabel();
        txtWaitRegen = new javax.swing.JTextField();
        lblWaitRegen = new javax.swing.JLabel();
        txtGestationTime = new javax.swing.JTextField();
        lblGestationTime = new javax.swing.JLabel();
        txtSightRadius = new javax.swing.JTextField();
        btnSightRadius = new javax.swing.JLabel();
        btnDiet = new javax.swing.JToggleButton();
        btnImport = new javax.swing.JButton();
        btnSave = new javax.swing.JButton();
        btnCancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new java.awt.GridBagLayout());

        lblName.setText("Species Name:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        getContentPane().add(lblName, gridBagConstraints);

        txtName.setPreferredSize(new java.awt.Dimension(75, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        getContentPane().add(txtName, gridBagConstraints);

        pnlColor.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        pnlColor.setPreferredSize(new java.awt.Dimension(20, 20));

        javax.swing.GroupLayout pnlColorLayout = new javax.swing.GroupLayout(pnlColor);
        pnlColor.setLayout(pnlColorLayout);
        pnlColorLayout.setHorizontalGroup(
            pnlColorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 16, Short.MAX_VALUE)
        );
        pnlColorLayout.setVerticalGroup(
            pnlColorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 16, Short.MAX_VALUE)
        );

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 8;
        gridBagConstraints.gridwidth = 2;
        getContentPane().add(pnlColor, gridBagConstraints);

        lblHealth.setText("Health:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        getContentPane().add(lblHealth, gridBagConstraints);

        txtHealth.setPreferredSize(new java.awt.Dimension(50, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        getContentPane().add(txtHealth, gridBagConstraints);

        txtHunger.setPreferredSize(new java.awt.Dimension(50, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        getContentPane().add(txtHunger, gridBagConstraints);

        lblHunger.setText("Hunger:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        getContentPane().add(lblHunger, gridBagConstraints);

        txtLifetime.setPreferredSize(new java.awt.Dimension(50, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        getContentPane().add(txtLifetime, gridBagConstraints);

        lblLifetime.setText("Life span:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        getContentPane().add(lblLifetime, gridBagConstraints);

        txtAttackPower.setPreferredSize(new java.awt.Dimension(50, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        getContentPane().add(txtAttackPower, gridBagConstraints);

        lblAttackPower.setText("Attack Power:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        getContentPane().add(lblAttackPower, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        getContentPane().add(txtMoveCost, gridBagConstraints);

        lblCosts.setText("Hunger costs");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        getContentPane().add(lblCosts, gridBagConstraints);

        lblMoveCost.setText("Move Cost:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        getContentPane().add(lblMoveCost, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        getContentPane().add(txtAtkCost, gridBagConstraints);

        lblAtkCost.setText("Attack Cost:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        getContentPane().add(lblAtkCost, gridBagConstraints);

        txtMateCost.setPreferredSize(new java.awt.Dimension(75, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        getContentPane().add(txtMateCost, gridBagConstraints);

        lblMateCost.setText("Mate Cost:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        getContentPane().add(lblMateCost, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        getContentPane().add(txtWaitCost, gridBagConstraints);

        lblWaitCost.setText("Wait Cost:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        getContentPane().add(lblWaitCost, gridBagConstraints);

        txtWaitRegen.setPreferredSize(new java.awt.Dimension(50, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        getContentPane().add(txtWaitRegen, gridBagConstraints);

        lblWaitRegen.setText("Regen rate:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        getContentPane().add(lblWaitRegen, gridBagConstraints);

        txtGestationTime.setPreferredSize(new java.awt.Dimension(50, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        getContentPane().add(txtGestationTime, gridBagConstraints);

        lblGestationTime.setText("Gestation:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        getContentPane().add(lblGestationTime, gridBagConstraints);

        txtSightRadius.setPreferredSize(new java.awt.Dimension(50, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        getContentPane().add(txtSightRadius, gridBagConstraints);

        btnSightRadius.setText("Sight Radius:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        getContentPane().add(btnSightRadius, gridBagConstraints);

        btnDiet.setText("Meat");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.gridwidth = 2;
        getContentPane().add(btnDiet, gridBagConstraints);

        btnImport.setText("Import");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 10;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        getContentPane().add(btnImport, gridBagConstraints);

        btnSave.setText("Save");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 10;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        getContentPane().add(btnSave, gridBagConstraints);

        btnCancel.setText("Cancel");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 10;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        getContentPane().add(btnCancel, gridBagConstraints);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancel;
    private javax.swing.JToggleButton btnDiet;
    private javax.swing.JButton btnImport;
    private javax.swing.JButton btnSave;
    private javax.swing.JLabel btnSightRadius;
    private javax.swing.JLabel lblAtkCost;
    private javax.swing.JLabel lblAttackPower;
    private javax.swing.JLabel lblCosts;
    private javax.swing.JLabel lblGestationTime;
    private javax.swing.JLabel lblHealth;
    private javax.swing.JLabel lblHunger;
    private javax.swing.JLabel lblLifetime;
    private javax.swing.JLabel lblMateCost;
    private javax.swing.JLabel lblMoveCost;
    private javax.swing.JLabel lblName;
    private javax.swing.JLabel lblWaitCost;
    private javax.swing.JLabel lblWaitRegen;
    private javax.swing.JPanel pnlColor;
    private javax.swing.JTextField txtAtkCost;
    private javax.swing.JTextField txtAttackPower;
    private javax.swing.JTextField txtGestationTime;
    private javax.swing.JTextField txtHealth;
    private javax.swing.JTextField txtHunger;
    private javax.swing.JTextField txtLifetime;
    private javax.swing.JTextField txtMateCost;
    private javax.swing.JTextField txtMoveCost;
    private javax.swing.JTextField txtName;
    private javax.swing.JTextField txtSightRadius;
    private javax.swing.JTextField txtWaitCost;
    private javax.swing.JTextField txtWaitRegen;
    // End of variables declaration//GEN-END:variables

    /**
     * @param parent the parent to set
     */
    public void setParent(Frame parent) {
        this.parent = parent;
    }
}
